package workflow.core;

import java.util.ArrayList;
import java.util.List;

import workflow.dto.WorkflowMessage;

public class WorkflowRunableBlock extends WorkflowBlock {

	public WorkflowRunableBlock() {
	}
	
	public WorkflowRunableBlock(String name,
			List<WorkflowRunableElement> elements) {
		this.name = name;
		this.elements = new ArrayList<WorkflowElement>();
		elements.addAll(elements);
	}
	
	public WorkflowRunableBlock(String name,
			WorkflowRunableElement element) {
		this.name = name;
		this.elements = new ArrayList<WorkflowElement>();
		elements.add(element);
	}

	@Override
	public int excecute() {
		outMessages = new ArrayList<WorkflowMessage>();
		for (WorkflowElement workflowElement : elements) {
			WorkflowRunableElement runableElement = (WorkflowRunableElement) workflowElement;
			runableElement.setInMessages(inMessages);
			runableElement.excecute();
			outMessages.addAll(runableElement.getOutMessages());
		}
		return 0;
	}

}
